<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
                *{
            padding: 0;
            margin: 0;
            list-style: none;
        }

        a{
            text-decoration: none;
        }
        
        .container{
            margin: 20px;
            border: 1px solid purple;
            position: relative;
            /* 如果绝对定位导致父元素塌陷，可以给父元素加上固定的高度来解决 */
            height: 300px;
        }

        .wrapper{
            width: 200px;
            height: 50px;
            border: 1px solid red;
        }
        .wrapper2{
            width: 50px;
            height: 50px;
            /* 固定定位，相对于浏览器窗口进行定位。 */
            position: fixed;
            right: 50px;
            top: 100px;
            background-color: #000;
            color: #fff;
            line-height: 50px;
            text-align: center;
            cursor: pointer;
        }
        .wrapper3{
            height: 200px;
        }
    </style>
</head>
<body>
    <a name="top">我是顶部</a>
    <div class="container">
        <div class="wrapper1 wrapper">

        </div>
        <div class="wrapper2 wrapper">
           <a href="#top" style="color: #fff;">去顶部</a> 
        </div>
        <div class="wrapper3 wrapper">

        </div>
        <div class="wrapper3 wrapper">

        </div>
        <div class="wrapper3 wrapper">

        </div>
        <div class="wrapper3 wrapper">

        </div>
        <div class="wrapper3 wrapper">

        </div>
        <div class="wrapper3 wrapper">

        </div>
        <div class="wrapper3 wrapper">

        </div>
    </div>
</body>
</html>